package controller;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JFrame;

import model.kwalificatiebeheer.Uitstroomrichting;
import model.kwalificatiebeheer.Werkproces;
import view.AddWerkprocesFrame;

public class AddWerkprocesPanelActions implements MouseListener,ActionListener {
	
	AddWerkprocesFrame sender;
	
	public AddWerkprocesPanelActions(AddWerkprocesFrame addWPanel){
		this.sender = addWPanel;
	}
	@Override
	public void actionPerformed(ActionEvent e) {
		if(e.getActionCommand().equals("btnSave")){
			Uitstroomrichting ur = sender.getUr();
			int id = 1;
			if(sender.getKt().getUitstroomWerkprocessen().get(ur) != null){
				id = sender.getKt().getUitstroomWerkprocessen().get(ur).size()+1;
			}
			Werkproces wp = new Werkproces(id, 
							sender.getTxtTitle().getText(), 
							sender.getTxtOmschrijving().getText(), 
							sender.getTxtGewensteResultaat().getText(), 
							sender.getTxtVakkennisVaardigheden().getText());
			sender.getKt().addWerkproces(ur, wp);
			System.out.println(wp);
			System.out.println(sender.getKt().getUitstroomWerkprocessen().get(ur));
			sender.dispose();
		}else if(e.getActionCommand().equals("btnSelecteren")){
			if(sender.getUr() != null){
				sender.initForm();
			}
		}
	}	
	@Override
	public void mouseClicked(MouseEvent e) {
		int row = sender.getUrTable().getSelectedRow();
		sender.setUr(sender.getUrs().get(row));
		if(e.getClickCount() == 2){
			if(sender.getUr() != null){
				sender.initForm();
			}
		}
	}
	@Override
	public void mouseEntered(MouseEvent e) {}
	@Override
	public void mouseExited(MouseEvent e) {}
	@Override
	public void mousePressed(MouseEvent e) {}
	@Override
	public void mouseReleased(MouseEvent e) {}
}
